#include "sample_raymarching.h"
int main()
{
	FrameBuffer<color> frameBuffer{ 800,600 };

	std::vector<uint8_t> shapeObjects;
	uint32_t top{ 0 };

	auto spere = new((top = shapeObjects.size(), shapeObjects.resize(sizeof(SphereShape)), &shapeObjects[top]))SphereShape();

	spere->radius = 5;
	spere->center.x = 0;
	spere->center.y = 0;
	spere->center.z = -20;

	generate_noise << < dim3(8, 1), dim3(32, 1) >> > ();
	
	auto d_image = (color*)d_malloc(frameBuffer.data_size());
	auto d_objects = (uint8_t*)d_malloc(shapeObjects.size());
	d_memcpy(d_objects, shapeObjects.data(), shapeObjects.size());
	synchronize();
	uint32_t frameCount{0};
	glShow("raymarthing", frameBuffer, GL_RGBA, [d_image, d_objects, &frameBuffer, &frameCount]
		{
			auto pre_time = std::chrono::high_resolution_clock::now();
			raymarching << < dim3(25, 19), dim3(32, 32) >> > (d_image, frameBuffer.width(), frameBuffer.height(), d_objects, 1, frameCount);
			synchronize();

			d_memcpy(frameBuffer.data(), d_image, frameBuffer.data_size(), false);
			synchronize();
			frameBuffer.dirty = true;
			frameCount++;
			auto duration = std::chrono::high_resolution_clock::now() - pre_time;
			return duration.count();
		});
	d_free(d_image); 
	d_free(d_objects); 
	//execute(print_param);
}